package vek.GUI.MapView;

import java.awt.Font;
import java.awt.Point;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import util.ImageGetter;
import vek.Objects.POI;
import vek.controllers.Map.MarkingsViewController;

/**
 * This is a JButton which represents a POI on the map. It can be clicked and info will be shown.
 * @author Christian, Michal og Jakob (Hold 1, gruppe 2)
 */
public class MarkingButton extends JButton{
    
    private Point location;
    private MarkingsViewController controller;
    private String nameOfPOI; // the name of the POI
    private POI poi; // the POI which this button represents
    
 /**
 * This is a JButton which represents a POI on the map. It can be clicked and info will be shown.
 * @param p coordinates determining the location of the MarkingButton on the map.
 * @param mvc the MarkingsViewController.
 * @param name the name of the POI the button represents.
 * @param po the POI-object the button represents.
 */
    public MarkingButton(Point p, MarkingsViewController mvc, String name, POI po)
    {
        controller = mvc;
        nameOfPOI = name;
        location = p;
        poi = po;

        ImageIcon notPressedIcon = new ImageIcon(ImageGetter.getImage("Data/images/poiicons/" + poi.getNotPressedIcon()));
        ImageIcon pressedIcon = new ImageIcon(ImageGetter.getImage("Data/images/poiicons/" + poi.getPressedIcon()));
       
        setBounds((int)p.getX(), (int)p.getY(), notPressedIcon.getIconWidth(), notPressedIcon.getIconHeight());
        setIcon(notPressedIcon);
        setPressedIcon(pressedIcon);
        
        
        setBorderPainted(false);
        setContentAreaFilled(false);
        addActionListener(controller);
      
    }
    
    /**
     * gets the POI which this button represents
     * @return the POI which this button represents
     */
    
    public POI getPOI()
    {
        return poi;
    }
    
    /**
     * gets the name of this POI
     * @return the name of the POI which this button represents
     */
    
    public String getNameOfPOI()
    {
        return nameOfPOI;
    }
    
    /**
     * Gets the location(X and Y coordinates) of this button
     * @return the X and Y pixel coordinates as a Point
     */
    
    public Point getLocationAsPoint()
    {
        Point returnedPoint = getBounds().getLocation();
        return returnedPoint;
    }
    /**
     * checks if this buttons location is the same as the given location
     * @param p the point of the location
     * @return true if this button has the exact same location as the given location
     */
    
    public boolean isLocation(Point p)
    {
        if( p.equals(location) )
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    /**
     * checks if this button has the same name as the parameter.
     * This method checks if the button has the same name as the paramter using the equalsIgnoreCase method.
     * <p>
     * NOTE: this method is NOT case sensitive
     * 
     * @param n the name if the button
     * @return true if the name of the button equals the string paramter
     */
    
    public boolean isName(String n)
    {
        if (n.equalsIgnoreCase(nameOfPOI))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    
   

}
